import { LineSegments } from 'three';
import type { CSSProperties,  } from 'react';

type OptionalKeys<T extends Record<string, unknown>> = {
  [K in keyof T]: T extends Record<K, T[K]> ? never : K;
}[keyof T];

type RequiredKeys<T extends Record<string, unknown>> = Exclude<keyof T, OptionalKeys<T>>;

type MonoArgEmitter<T, Keys extends keyof T> = <K extends Keys>(evt: K, arg?: T[K]) => void;

type BiArgEmitter<T, Keys extends keyof T> = <K extends Keys>(evt: K, arg: T[K]) => void;

export type EventEmitter<T extends Record<string, unknown>> = MonoArgEmitter<T, OptionalKeys<T>> &
  BiArgEmitter<T, RequiredKeys<T>>;

export type AnyFunction<T> = (...args: any[]) => T;

export type PartialReturnType<T extends (...args: unknown[]) => unknown> = Partial<ReturnType<T>>;

// export type SFCWithInstall<T> = T & Plugin;
export type SFCWithInstall<T> = T ;
export type Nullable<T> = T | null;

export type RefElement = Nullable<HTMLElement>;

export type CustomizedHTMLElement<T> = HTMLElement & T;

export type Indexable<T> = {
  [key: string]: T;
};

export type Hash<T> = Indexable<T>;

export type TimeoutHandle = ReturnType<typeof global.setTimeout>;

export type ComponentSize = 'large' | 'medium' | 'small' | 'mini';

export type StyleValue = string | CSSProperties | Array<StyleValue>;

export type Mutable<T> = { -readonly [P in keyof T]: T[P] };

// threeJs interface
export interface Options {
  // viewContainer: HTMLElement;
  [key: string]: any;
}

export interface ZoomOptions {
  fitOffset: number;
}

export interface SphereOptions {
  // name: Nullable<string>;
  name:string;
  radius?: number;
  // joinToScene?: boolean;
  color?: string;
}

export interface SceneOptions {
  gridVisible?: boolean;
  groundPlaneVisible?: boolean;
}

export interface IFace {
  face_index: number;
  normal_coord: number[];
  number_of_triangles: number;
  tri_indexes: number[];
  uv_coord: number[];
  vertex_coord: number[];
}

export interface IEdge {
  edge_index: number;
  vertex_coord: number[];
}

export interface IVertex {
  vertex_coord: number[];
}

export interface Metadata {
  start?: number;
  end?: number;
}

export interface FaceMetadata extends Metadata {
  localFaceIndex?: number;
}

export interface EdgeMetadata extends Metadata {
  localEdgeIndex?: number;
}

export interface GlobalMetadata extends Metadata {
  [key: number]: Metadata;
}

export interface ILine extends LineSegments {
  globalEdgeIndices?: number[];
  lineColors?: number[];
  globalEdgeMetadata?: GlobalMetadata;
  highlightEdgeAtLineIndex?: Fn;
  getEdgeMetadataAtLineIndex?: Fn;
  clearHighlights?: Fn;
}
